<template>
	<view class="">
		<u-scroll-list :indicator="indicator" >
			<view class="parentCategory">
				<view v-for="(item, index) in newList" :key="item.value"
					:class="inx == index?'afterScrollItem':'scrollItem'" :id="index" @click="getChildrenList">
					{{ item.label }}
				</view>
			</view>
		</u-scroll-list>
		<!-- 子级服务 -->
		<view class="cate-section">
			<view v-for="(item, index) in childrenCategoryList" class="cate-item" @click="goService(item)">
				<image :src="item.url" />
				<text>{{ item.label }}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				inx: 0,
				indicator: false,
				newList: [],
				childrenCategoryList: []
			}
		},
		onLoad() {
			this.getCategoryList()
		},
		methods: {
			getChildrenList(e) {
				this.inx = e.currentTarget.id
				this.childrenCategoryList = this.newList[this.inx].children
			},
			getCategoryList() {
				this.$api.request('serve', 'tree').then(res => {
					this.newList = res.data
					this.childrenCategoryList = this.newList[0].children
				})
			},
			goService(item) {
				uni.navigateTo({
					url: '/pages/index/service?id=' + item.value
				})
			}
		}
	}
</script>

<style>
	.cate-section {
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		padding: 10rpx 20rpx;
		/* margin-top: -20rpx; */

	}

	.cate-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: $font-sm + 2upx;
		color: $font-color-dark;
		padding: 16rpx 30rpx;
	}

	image {
		width: 88upx;
		height: 88upx;
		margin-bottom: 14upx;
		border-radius: 50%;
		// opacity: 0.7;
		/* box-shadow: 4upx 4upx 20upx rgba(250, 67, 106, 0.3); */
	}

	.parentCategory {
		/* width: 100%; */
		background-color: #fff;
		display: flex;
		border-bottom: 1px solid #f5f5f5;
		align-items: center;
		font-size: 24rpx;
	}

	.scrollItem {
		margin: 20rpx 10rpx 20rpx 10rpx;
		overflow: hidden;
		width: 200rpx;
		height: 60rpx;
		color: #999;
		text-align: center;
		line-height: 60rpx;
	}

	.afterScrollItem {
		margin: 20rpx 10rpx 20rpx 10rpx;
		overflow: hidden;
		width: 200rpx;
		height: 60rpx;
		text-align: center;
		line-height: 60rpx;
		background-color: orangered;
		color: #fff;
		border-radius: 45rpx;
	}
</style>
